home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvlabel.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-05  |  3.0 KB  |  132 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVLABEL.CPP                          |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Items labels implementation          |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_string
  16. #define uses_basics
  17. #define uses_cmd
  18. #define uses_dc
  19. #define uses_icons
  20. #define uses_label
  21. #define uses_system
  22.  
  23. #include "PVuses.h"
  24.  
  25. //Tlabel publics:
  26.  
  27. Tlabel::Tlabel( char *t, Titem *i ):
  28.   Titem( 0, 1 )
  29. {
  30.   set_flags( ifSELECTABLE, 0 );
  31.   title = STRDUP( t );
  32.   resize( smart_len( t ), 1 );
  33.   shortcut = get_shortcut( t );
  34.   item = i;
  35. }
  36.  
  37. Tlabel::~Tlabel( void )
  38. {
  39.   FREE( title );
  40. }
  41.  
  42. //Tlabel protected:
  43.  
  44. void Tlabel::set_palette( void )
  45. {
  46.   Titem::set_palette();
  47.   if( item == NULL ) return;
  48.   if( item->state( isDISABLED ) ) shortcut_attr = disabled_attr;
  49. }
  50.  
  51. void Tlabel::draw( void )
  52. {
  53.   char *s;
  54.  
  55.   if( title == NULL ) return;
  56.   s = "";
  57.   if( item != NULL )
  58.   {
  59.     if( item->state( isDISABLED ) )
  60.       s = "|d";
  61.     else
  62.       if( item->state( isSELECTED ) )
  63.         s = "|b";
  64.   }
  65.   txtf( "%s%s", s, title );
  66. }
  67.  
  68. void Tlabel::event_handler( Tevent &ev )
  69. {
  70.   switch( ev.code )
  71.   {
  72.     case evKEY_PRESS:
  73.       if( ev.ASCII==shortcut && item!=NULL && !item->state(isHIDDEN|isDISABLED) )
  74.       {
  75.         item->focus();
  76.         message( item, cmLABEL_FOCUSED );
  77.         handled(ev);
  78.         return;
  79.       }
  80.       break;
  81. #ifndef NOMOUSE
  82.     case evMOUSE_DOWN:
  83.       if( ev.INSIDE )
  84.       {
  85.         item->focus();
  86.         handled(ev);
  87.         return;
  88.       }
  89.       break;
  90. #endif
  91.   }
  92.   Titem::event_handler( ev );
  93. }
  94.  
  95. //Tbox publics:
  96.  
  97. Tbox::Tbox( char *t, Titem *i ):
  98.   Tlabel( t, i )
  99. {
  100.   if( item != NULL )
  101.   {
  102.     item->optimize_bounds();
  103.     resize( item->bound_xl + 2, item->bound_yl + 2 );
  104.   }
  105.   title_len = (char) smart_len( t );
  106. }
  107.  
  108. //Tbox potected:
  109.  
  110. boolean Tbox::check_inside( int _x, int _y )
  111. {
  112.   int a,b;
  113.   get_origin( a, b );
  114.   return Tlabel::check_inside( _x, _y ) &&
  115.          ( _x==a || _x==a+xl-1 || _y==b );//|| _y==b+yl-1 );
  116. }
  117.  
  118. void Tbox::draw( void )
  119. {
  120.   static char t[] = "|r...|n.|l..|r...";
  121.   static char s[] = " |l.";
  122.  
  123.   txt( i_box_ul ); Tlabel::draw();
  124.   t[2] = (char) ( xl - title_len - 2 ); t[3] = frame_standard[1];
  125.   t[4] = i_box_ur[0]; t[7] = frame_normal[3]; t[10] = (char) ( yl - 2 );
  126.   t[11] = i_box_dl[0]; t[14] = (char) ( xl - 2 ); t[15] = frame_normal[1];
  127.   t[16] = i_box_dr[0];
  128.   txt( t );
  129.   s[0] = frame_normal[5]; s[3] = (char) ( yl - 2 );
  130.   set_base( current_dc->base_x + xl - 1, current_dc->base_y + 1 ); txt( s );
  131. }
  132.